using Microsoft.AspNetCore.Mvc;
using ZR.Service.Business.IBusinessService;
using ZR.Admin.WebApi.Filters;
using ZR.Service.IService.ProductionControl;
using ZR.Model.Dto.Business.ProductionControl;
using ZR.Model.Models.ProductionControl;

//创建时间：2024-09-29
namespace ZR.Admin.WebApi.Controllers
{
    /// <summary>
    /// 工位配置表
    /// </summary>
    [Verify]
    [Route("run/workstationconfig")]
    [ApiExplorerSettings(GroupName = "business")]
    public class WorkstationConfigController : BaseController
    {
        /// <summary>
        /// 工位配置表接口
        /// </summary>
        private readonly IWorkstationConfigService _WorkstationConfigService;

        public WorkstationConfigController(IWorkstationConfigService WorkstationConfigService)
        {
            _WorkstationConfigService = WorkstationConfigService;
        }

        /// <summary>
        /// 查询工位配置表列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "run:workstationconfig:list")]
        public IActionResult QueryWorkstationConfig([FromQuery] WorkstationConfigQueryDto parm)
        {
            var response = _WorkstationConfigService.GetList(parm);
            return SUCCESS(response);
        }

        /// <summary>
        /// 查询工位配置表详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        [ActionPermissionFilter(Permission = "run:workstationconfig:query")]
        public IActionResult GetWorkstationConfig(int Id)
        {
            var response = _WorkstationConfigService.GetInfo(Id);

            var info = response.Adapt<WorkstationConfigDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加工位配置表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "run:workstationconfig:add")]
        [Log(Title = "工位配置表", BusinessType = BusinessType.INSERT)]
        public IActionResult AddWorkstationConfig([FromBody] WorkstationConfigDto parm)
        {
            var modal = parm.Adapt<WorkstationConfig>().ToCreate(HttpContext);

            var response = _WorkstationConfigService.AddWorkstationConfig(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新工位配置表
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "run:workstationconfig:edit")]
        [Log(Title = "工位配置表", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateWorkstationConfig([FromBody] WorkstationConfigDto parm)
        {
            var modal = parm.Adapt<WorkstationConfig>().ToUpdate(HttpContext);
            var response = _WorkstationConfigService.UpdateWorkstationConfig(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除工位配置表
        /// </summary>
        /// <returns></returns>
        [HttpDelete("delete/{ids}")]
        [ActionPermissionFilter(Permission = "run:workstationconfig:delete")]
        [Log(Title = "工位配置表", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteWorkstationConfig([FromRoute] string ids)
        {
            var idArr = Tools.SplitAndConvert<int>(ids);

            return ToResponse(_WorkstationConfigService.Delete(idArr));
        }
    }
}